package com.example.book.controller;


import com.example.book.service.UserService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    //    账号密码不是固定的了，就得从数据库中取
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session) {
        //打印日志头打一个尾部打一个
        log.info("接受到的参数：" + name);
//        //账号密码为空时

//        if(!StringUtils.hasLength(name)||!StringUtils.hasLength(password)){
//            return false;
//        }
//        //模拟验证数据，账号密码正确
//        if("admin".equals(name)&&"admin".equals(password)){
//           session.setAttribute("userName",name);
//            session.setAttribute("password",password);
//            return true;
//        }
//
//        //账号密码正确
//        return false;

        Boolean result= userService.checkUserAndPassword(name,password,session);
        log.info("用户登录结果：name:{},结果{}",name,result);
        return result;

    }
}

